/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Utility;

import java.io.UnsupportedEncodingException;

/**
 *
 * @author Hmong
 */
public class EncodingUtility {
    public static boolean IsEncodingSupported(String encoding) {
        boolean bRet = true;
        try {
            "0".getBytes(encoding);
        } catch (UnsupportedEncodingException ueex) {
            bRet = false;
        }

        return bRet;
    }

    public static String GetSupportedEncodings(){
        String[] encodingNames = {"ASCII", "UTF7", "UTF-7", "UTF_7", "UTF8", "UTF-8", "UTF_8", "UTF-16", "UTF16", "UTF_16", "UTF32", "UTF-32", "UTF_32", "UNICODE", "Big5", "GBK", "GB2312", "GB18030"};
        String strRet = "";

        for(int i=0; i<encodingNames.length; i++){
            if (IsEncodingSupported(encodingNames[i].toUpperCase())){
                strRet += encodingNames[i].toUpperCase() + "\r\n";
                //System.out.println("Supported Encoding: " + encodingNames[i]);
            }

            if (IsEncodingSupported(encodingNames[i].toLowerCase())){
                strRet += encodingNames[i].toLowerCase() + "\r\n";
                //System.out.println("Supported Encoding: " + encodingNames[i]);
            }
        }

        return strRet;
    }
}
